<script setup>
import {onMounted, reactive, ref} from "vue";
import router from "@/router";
import {$ajax, apiUrl} from "@/utils/ajax";

const page = ref(1)
const lastPage = ref(1)
const order = reactive([])
const orderLst = ref()
onMounted(() => {
  // store.dispatch("getUser")
  // alert()
  getOrder()
})
const getOrder = () => {
  $ajax.post(`${apiUrl}merchant/order/orderLst`, {page: page.value}).then(({data: {result: {lst, last_page}}}) => {
    lastPage.value = last_page
    if (page.value === 1) {
      order.slice(0, order.length)
    }
    order.push(...lst)
  })
}
</script>

<template>
  <div class="back" @click="router.replace({name:'home'})">
    <el-icon size="16">
      <ArrowLeft/>
    </el-icon>
    <div>兑换记录</div>
  </div>
  <el-scrollbar class="order-lst" ref="orderLst" v-if="order.length">
    <el-card shadow="never" v-for="ord in order" :key="ord.id">
      <div class="order-items">
        <div class="order-images">
          <el-image :src="ord?.gift?.image"/>
        </div>
        <div class="order-info">
          <h3>{{ ord?.gift?.name }}</h3>
          <div>
            <el-text type="info">
              兑换码：{{ ord?.code }}
            </el-text>
          </div>
          <div>
            <el-text type="info">
              手机号：{{ ord?.mobile }}
            </el-text>
          </div>
          <div>
            <el-text type="info">
              领取时间：{{ ord?.draw_time }}
            </el-text>
          </div>
        </div>
      </div>
    </el-card>
    <div class="not-more" v-if="page >= lastPage">
      暂时没有更多兑换记录了~
    </div>
  </el-scrollbar>
  <el-empty v-else/>
</template>

<style scoped lang="less">

.order-lst {
  height: calc(100vh - 80px);
  width: 100%;
  box-sizing: border-box;
  padding: 0 15px;

  .el-card{
    margin-bottom: 15px;

    .order-items{
      display: flex;
      align-items: center;

      .order-images{
        width: 100px;
        flex-basis: 100px;
        margin-right: 10px;
      }

      .order-info{
        line-height: 1.45;

        .el-text{
          font-size: .8rem;
        }
      }
    }
  }
}

</style>